package org.gap.service;

import java.util.List;
import java.util.Set;

import org.gap.dao.PersistentLoginsDAO;

import org.gap.domain.PersistentLogins;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring service that handles CRUD requests for PersistentLogins entities
 * 
 */

@Service("PersistentLoginsService")
@Transactional
public class PersistentLoginsServiceImpl implements PersistentLoginsService {

	/**
	 * DAO injected by Spring that manages PersistentLogins entities
	 * 
	 */
	@Autowired
	private PersistentLoginsDAO persistentLoginsDAO;

	/**
	 * Instantiates a new PersistentLoginsServiceImpl.
	 *
	 */
	public PersistentLoginsServiceImpl() {
	}

	/**
	 * Delete an existing PersistentLogins entity
	 * 
	 */
	@Transactional
	public void deletePersistentLogins(PersistentLogins persistentlogins) {
		persistentLoginsDAO.remove(persistentlogins);
		persistentLoginsDAO.flush();
	}

	/**
	 */
	@Transactional
	public PersistentLogins findPersistentLoginsByPrimaryKey(String series) {
		return persistentLoginsDAO.findPersistentLoginsByPrimaryKey(series);
	}

	/**
	 * Return a count of all PersistentLogins entity
	 * 
	 */
	@Transactional
	public Integer countPersistentLoginss() {
		return ((Long) persistentLoginsDAO.createQuerySingleResult("select count(o) from PersistentLogins o").getSingleResult()).intValue();
	}

	/**
	 * Load an existing PersistentLogins entity
	 * 
	 */
	@Transactional
	public Set<PersistentLogins> loadPersistentLoginss() {
		return persistentLoginsDAO.findAllPersistentLoginss();
	}

	/**
	 * Save an existing PersistentLogins entity
	 * 
	 */
	@Transactional
	public void savePersistentLogins(PersistentLogins persistentlogins) {
		PersistentLogins existingPersistentLogins = persistentLoginsDAO.findPersistentLoginsByPrimaryKey(persistentlogins.getSeries());

		if (existingPersistentLogins != null) {
			if (existingPersistentLogins != persistentlogins) {
				existingPersistentLogins.setSeries(persistentlogins.getSeries());
				existingPersistentLogins.setUsername(persistentlogins.getUsername());
				existingPersistentLogins.setToken(persistentlogins.getToken());
				existingPersistentLogins.setLastUsed(persistentlogins.getLastUsed());
			}
			persistentlogins = persistentLoginsDAO.store(existingPersistentLogins);
		} else {
			persistentlogins = persistentLoginsDAO.store(persistentlogins);
		}
		persistentLoginsDAO.flush();
	}

	/**
	 * Return all PersistentLogins entity
	 * 
	 */
	@Transactional
	public List<PersistentLogins> findAllPersistentLoginss(Integer startResult, Integer maxRows) {
		return new java.util.ArrayList<PersistentLogins>(persistentLoginsDAO.findAllPersistentLoginss(startResult, maxRows));
	}
}
